//
//  orderCell.m
//  有材网
//
//  Created by 肖扬 on 16/1/31.
//  Copyright © 2016年 肖扬. All rights reserved.
//

#import "orderCell.h"

@implementation orderCell
@synthesize titleLab,statusLab,describeLab,priceLab,smallImg;
- (void)awakeFromNib {
    // Initialization code
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        
        UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(0, 10, SWIDTH, 135)];
        tempView.backgroundColor = [UIColor whiteColor];
        [self addSubview:tempView];
        
        UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, (37-11)/2, 12, 11)];
        imgView.image= [UIImage imageNamed:@"店铺"];
        imgView.backgroundColor = [UIColor clearColor];
        [tempView addSubview:imgView];
        
        self.titleLab = [self createLabelFrame:CGRectMake(27, (37-12)/2, SWIDTH - 110, 12) title:@"" titleColor:[UIColor blackColor] tag:0];
        self.titleLab.font = [UIFont systemFontOfSize:12];
        [tempView addSubview:self.titleLab];
        
        self.statusLab = [self createLabelFrame:CGRectMake(SWIDTH -80, (37-12)/2, 70, 12) title:@"" titleColor:BLUEColor tag:0];
        self.statusLab.font = [UIFont systemFontOfSize:12];
        self.statusLab.textAlignment = NSTextAlignmentRight;
        [tempView addSubview:self.statusLab];
        
        XlineView *lineView = [[XlineView alloc]initWithFrame:CGRectMake(10, 36.5, SWIDTH - 20, 0.5)];
        lineView.backgroundColor = [UIColor grayColor];
        lineView.alpha = 0.2;
        [tempView addSubview:lineView];
        
        self.smallImg = [[EGOImageView alloc]initWithPlaceholderImage:[UIImage imageNamed:@"默认加载图片"]];
        smallImg.frame = CGRectMake(10, 42, 56, 56);
        smallImg.backgroundColor = [UIColor clearColor];
        [smallImg setContentMode:UIViewContentModeScaleToFill];
//        [smallImg setContentMode:UIViewContentModeScaleAspectFill];
        [tempView addSubview:self.smallImg];
        
        self.describeLab = [self createLabelFrame:CGRectMake(71, (62 - 12)/2+37, SWIDTH - 86, 12) title:@"" titleColor:[UIColor blackColor] tag:0];
        self.describeLab.font = [UIFont systemFontOfSize:14];
        [tempView addSubview:self.describeLab];
        
        XlineView *lineView1 = [[XlineView alloc]initWithFrame:CGRectMake(10, 102.5, SWIDTH - 20, 0.5)];
        lineView1.backgroundColor = [UIColor grayColor];
        lineView1.alpha = 0.2;
        [tempView addSubview:lineView1];
        
        UILabel *lab = [self createLabelFrame:CGRectMake(10, (37 - 12)/2+100, 40, 12) title:@"总价:" titleColor:BLACKColor tag:0];
        lab.font = [UIFont systemFontOfSize:12];
        [tempView addSubview:lab];
        
        self.priceLab = [self createLabelFrame:CGRectMake(50, (37 - 12)/2+100, SWIDTH - 20, 12) title:@"" titleColor:UIColorFromRGB(0xd90016) tag:0];
        self.priceLab.font = [UIFont systemFontOfSize:12];
        [tempView addSubview:self.priceLab];
    }
    return self;
}
-(void)drawCell:(id)model{
    homeModelSupply *order = (homeModelSupply *)model;
    if (![Unity isBlankString:order.company_name]) {
        self.titleLab.text = order.company_name;
    }
    [self.smallImg setImage:[UIImage imageNamed:@"默认加载图片"]];
    if (![Unity isBlankString:order.pics]) {
        if (![Unity isBlankString:[order.pics objectForKey:@"thumb100x100"]]) {
            NSMutableArray *arr = [order.pics objectForKey:@"thumb100x100"];
            if ([arr count]!=0) {
                [self.smallImg setImageURL:[NSURL URLWithString:[arr objectAtIndex:0]]];
                self.smallImg.frame = CGRectMake(10, 42, 51, 51);
            }
        }
    }
//    if (![Unity isBlankString:order.material_name]){
//        self.describeLab.text = order.material_name;
//    }
    if (![Unity isBlankString:order.title]) {
        self.describeLab.text = order.title;
    }else{
        NSString *title = @"";
        if (![Unity isBlankString:order.brand_name]) {
            title = [title stringByAppendingString:[NSString stringWithFormat:@"%@",order.brand_name]];
        }
        if (![Unity isBlankString:order.material_name]) {
            title = [title stringByAppendingString:[NSString stringWithFormat:@" %@",order.material_name]];
        }
        self.describeLab.text = title;
    }
    
    if (![Unity isBlankString:order.price]){
        self.priceLab.text = [NSString stringWithFormat:@"%@元",order.price];
    }
    if (![Unity isBlankString:order.status]) {
        if ([order.status isEqualToString:@"payed"]) {
            self.statusLab.text = @"已付款";
        }else if ([order.status isEqualToString:@"unpay"]){
            self.statusLab.text = @"待付款";
        }else if ([order.status isEqualToString:@"shipment"]){
            self.statusLab.text = @"已发货";
        }else if ([order.status isEqualToString:@"success"]){
            self.statusLab.text = @"交易成功";
        }else if ([order.status isEqualToString:@"cancel"]){
            self.statusLab.text = @"交易关闭";
        }
    }
}
//创建UILabel  tag值为三位数
- (UILabel *)createLabelFrame:(CGRect)frame
                        title:(NSString *)title
                   titleColor:(UIColor *)color
                          tag:(NSInteger)tag{
    UILabel *tempLabel = [[UILabel alloc]initWithFrame:frame];
    [tempLabel setBackgroundColor:[UIColor clearColor]];
    [tempLabel setText:title];
    [tempLabel setTag:tag];
    [tempLabel setTextColor:color];
    return tempLabel;
}
//创建UIButton tag值为四位数
- (UIButton *)createButtonFrame:(CGRect)frame
                          title:(NSString *)title
                 viewController:(id)viewController
                       selector:(SEL)selector
                            tag:(NSInteger)tag{
    UIButton *tempButton = [UIButton buttonWithType:0];
    [tempButton setFrame:frame];
    [tempButton setTag:tag];
    [tempButton setBackgroundColor:[UIColor clearColor]];
    [tempButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tempButton setTitle:title forState:UIControlStateNormal];
    [tempButton addTarget:viewController action:selector forControlEvents:UIControlEventTouchUpInside];
    return tempButton;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
